package com.javabean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

@Component("u1")
@Scope("prototype")
public class User {
    @Value("1")
    private int id;
    @Value("张三")
    private String name;
    @Value("18")
    private int age;
    @Resource
    private Role r;

    public User() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Role getR() {
        return r;
    }

    public void setR(Role r) {
        this.r = r;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", r=" + r +
                '}';
    }
    @PostConstruct
    public void a(){
        System.out.println("初始化方法启动！");
    }
    @PreDestroy
    public void b(){
        System.out.println("销毁方法启动！");
    }
}
